package yxy.game.pm2.active.command.turntable;

import yxy.apple.logger.Logger;
import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.module.ActiveModule_夺宝;
import yxy.game.pm2.bean.PlayerBean;
import yxy.game.pm2.bean.ServerBean;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;
import yxy.game.pm2.message.ActiveMessage.ActTurnTableInfoRequest;

@MessageType(proto = Command.ActTurnTableInfo, classtype = ActiveMessage.ActTurnTableInfoRequest.class)
public class CMD_Active_夺宝_Info extends Command<ActTurnTableInfoRequest> {

	private static final Logger logger = Logger.create(CMD_Active_夺宝_Info.class);
	
	@Override
	public void execute(MessageSource messageSource, ActTurnTableInfoRequest request) throws Exception {
		String playercode = messageSource.getTag();
		ActiveMessage.ActTurnTableInfoResponse.Builder response = ActiveMessage.ActTurnTableInfoResponse.newBuilder();
		
		ActiveModule_夺宝 am = ActiveModule_夺宝.get(playercode,false);
		if(am == null) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
		
		if(!am.running()) {
			send(messageSource, response, Result.ActNoOpen);
			return;
		}
		
		PlayerBean pb = PlayerBean.get(playercode);
		ServerBean sb = ServerBean.get(pb.getServerId());
		
		/****************/
	
		response.addTurntableinfo(am.deal(sb.getAreaId(), ActiveModule_夺宝.普通夺宝));
		response.addTurntableinfo(am.deal(sb.getAreaId(), ActiveModule_夺宝.高级夺宝));
		
		send(messageSource, response, Result.Success);
	}

	private void send(MessageSource messageSource, ActiveMessage.ActTurnTableInfoResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
	
}
